package Webpage;
import AutoTest.AutoFun;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import java.time.Duration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-09-10
 * Time: 1:25
 */
public class Personal {
    private WebDriver driver=null;
    private String url="http://8.155.1.153/?s=user/index.html";
    public void test(){
        driver= AutoFun.getDriver();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div/ul[2]/div[1]/div/a")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        test1();//修改头像
        System.out.println("修改头像测试完成");
        test2();//修改个人资料
        System.out.println("修改个人资料测试完成");
        test3();//修改我的地址
        System.out.println("修改我的地址测试完成");
        System.out.println("个人中心测试完成");
    }
    private void test1(){
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[4]/div[3]/div/div[1]/div[1]/div[2]/a[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("//*[@id=\"user-avatar-popup\"]/div/div[2]/form/div[2]/button[1]"));
        driver.findElement(By.xpath("//*[@id=\"user-avatar-popup\"]/div/div[2]/form/div[2]/button[2]"));
        driver.findElement(By.xpath("//*[@id=\"user-avatar-popup\"]/div/div[2]/form/div[2]/div/input")).sendKeys("E:/IDEA/code/java/Selenium/ShoppingAuto/src/test/images/test.png");
        driver.findElement(By.xpath("//*[@id=\"user-avatar-popup\"]/div/div[2]/form/div[4]/button[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[4]/div[3]/div/div[1]/div[1]/div[2]/a[2]"));
    };
    private void test2(){
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[4]/div[3]/div/div[1]/div[1]/div[2]/a[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/dl/dd[6]/span[2]/a")).click();
        //不输出手机号进行设置
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        //输入错误的手机号进行设置
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).sendKeys("1231234");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        //输入正确的手机号进行设置
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).sendKeys("18712341234");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        driver.findElement(By.xpath("//*[@id=\"collapse-nav-base\"]/li[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        //不输入邮箱进行设置
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/dl/dd[7]/span[2]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        //输入错误的邮箱进行设置
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).sendKeys("123123123");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        //输入正确的邮箱进行设置
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"accounts\"]")).sendKeys("1234567890@qq.com");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[3]/button")).click();
        driver.findElement(By.xpath("//*[@id=\"collapse-nav-base\"]/li[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        //不输入昵称进行设置
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/div/a")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[1]/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[2]/button")).click();
        //输入错误格式的昵称进行设置
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[1]/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[1]/div[1]/input")).sendKeys("1111111111111111111111111111111111111111111111111111111111111");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[2]/button")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        //输入正确格式的昵称进行设置
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/div/a")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[1]/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[1]/div[1]/input")).sendKeys("Auto4059");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/form/div[2]/button")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[1]/div/ul[2]/div[2]/div/a")).click();
    };
    private void test3(){
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[4]/div[3]/div/div[1]/div[1]/div[2]/a[3]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div[3]/div[3]/div/div[2]/button")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        //错误设置地址
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[3]/input")).clear();
        driver.findElement(By.xpath("//*[@id=\"form-address\"]")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[7]/button[2]")).click();
        //正确设置地址
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[1]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[1]/input")).sendKeys("name");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[3]/input")).clear();
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[3]/input")).sendKeys("18712341234");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[4]/div/div[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[4]/div/div[1]/div[2]/div[1]/div[1]/div/ul/li[1]")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[4]/div/div[1]/div[2]/div[1]/div[2]/div/ul/li")).click();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(3));
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[4]/div/div[1]/div[2]/div[1]/div[3]/div/ul/li[1]")).click();
        driver.findElement(By.xpath("//*[@id=\"form-address\"]")).clear();
        driver.findElement(By.xpath("//*[@id=\"form-address\"]")).sendKeys("Auto123号");
        driver.findElement(By.xpath("/html/body/div[1]/div[1]/div/form/div[7]/button[2]")).click();
    };
}
